/**
 * 
 */
package com.effectiv.gooruda.rest.api.controller;

import org.springframework.social.facebook.api.Facebook;
import org.springframework.social.facebook.api.FacebookLink;
import org.springframework.social.facebook.api.LinkPost;
import org.springframework.social.facebook.api.NotePost;
import org.springframework.social.facebook.api.PagedList;
import org.springframework.social.facebook.api.PagingParameters;
import org.springframework.social.facebook.api.Post;
import org.springframework.social.facebook.api.StatusPost;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * @author Dhrubo
 * 
 */
@Controller
@RequestMapping("/api/facebook/feed")
public class FacebookFeedOperationsController {

	@RequestMapping(value = "/deletepost/{id}", method = RequestMethod.DELETE)
	public void deletePost(@PathVariable("id") String id, Facebook facebook) {
		facebook.feedOperations().deletePost(id);
	}
	
	@RequestMapping(value = "/getfeed", method = RequestMethod.GET)
	public PagedList<Post> getFeed(PagingParameters pagedListParameters,
			Facebook facebook) {
		return facebook.feedOperations().getFeed(pagedListParameters);
	}

	@RequestMapping(value = "/getfeed/{ownerId}", method = RequestMethod.GET)
	public PagedList<Post> getFeed(@PathVariable("ownerId") String ownerId,
			PagingParameters pagedListParameters, Facebook facebook) {
		return facebook.feedOperations().getFeed(ownerId, pagedListParameters);
	}

	@RequestMapping(value = "/gethomefeed", method = RequestMethod.GET)
	public PagedList<Post> getHomeFeed(PagingParameters pagedListParameters,
			Facebook facebook) {
		return facebook.feedOperations().getHomeFeed(pagedListParameters);
	}

	@RequestMapping(value = "/getlinks", method = RequestMethod.GET)
	public PagedList<LinkPost> getLinks(PagingParameters pagedListParameters,
			Facebook facebook) {
		return facebook.feedOperations().getLinks(pagedListParameters);
	}

	@RequestMapping(value = "/getlinks/{ownerId}", method = RequestMethod.GET)
	public PagedList<LinkPost> getLinks(String ownerId,
			PagingParameters pagedListParameters, Facebook facebook) {
		return facebook.feedOperations().getLinks(ownerId, pagedListParameters);
	}

	@RequestMapping(value = "/getnotes", method = RequestMethod.GET)
	public PagedList<NotePost> getNotes(PagingParameters pagedListParameters,
			Facebook facebook) {
		return facebook.feedOperations().getNotes(pagedListParameters);
	}
	
	@RequestMapping(value = "/getnotes/{ownerId}", method = RequestMethod.GET)
	public PagedList<NotePost> getNotes(String ownerId,
			PagingParameters pagedListParameters, Facebook facebook) {
		return facebook.feedOperations().getNotes(ownerId, pagedListParameters);
	}
	
	@RequestMapping(value = "/getpost/{entryId}", method = RequestMethod.GET)
	public Post getPost(String entryId, Facebook facebook) {
		return facebook.feedOperations().getPost(entryId);
	}

	
	@RequestMapping(value = "/getposts", method = RequestMethod.GET)
	public PagedList<Post> getPosts(PagingParameters pagedListParameters,
			Facebook facebook) {
		return facebook.feedOperations().getPosts(pagedListParameters);
	}
	
	
	@RequestMapping(value = "/getposts/{ownerId}", method = RequestMethod.GET)
	public PagedList<Post> getPosts(String ownerId,
			PagingParameters pagedListParameters, Facebook facebook) {
		return facebook.feedOperations().getPosts(ownerId, pagedListParameters);
	}

	
	@RequestMapping(value = "/getstatuses", method = RequestMethod.GET)
	public PagedList<StatusPost> getStatuses(
			PagingParameters pagedListParameters, Facebook facebook) {
		return facebook.feedOperations().getStatuses(pagedListParameters);
	}
	
	@RequestMapping(value = "/getstatuses/{userId}", method = RequestMethod.GET)
	public PagedList<StatusPost> getStatuses(String userId,
			PagingParameters pagedListParameters, Facebook facebook) {
		return facebook.feedOperations().getStatuses(userId,
				pagedListParameters);
	}
	
	@RequestMapping(value = "/post/{ownerId}/{message}", method = RequestMethod.POST)
	public String post(String ownerId, String message, Facebook facebook) {
		return facebook.feedOperations().post(ownerId, message);
	}
	
	@RequestMapping(value = "/postlink/{message}", method = RequestMethod.POST)
	public String postLink(String message, FacebookLink link, Facebook facebook) {
		return facebook.feedOperations().postLink(message, link);
	}
	
	@RequestMapping(value = "/postlink/{ownerId}/{message}", method = RequestMethod.POST)
	public String postLink(String ownerId, String message, FacebookLink link,
			Facebook facebook) {
		return facebook.feedOperations().postLink(ownerId, message, link);
	}

	
	@RequestMapping(value = "/searchhomefeed/{query}", method = RequestMethod.GET)
	public PagedList<Post> searchHomeFeed(String query,
			PagingParameters pagedListParameters, Facebook facebook) {
		return facebook.feedOperations().searchHomeFeed(query,
				pagedListParameters);
	}
	
	@RequestMapping(value = "/searchpublicfeed/{query}", method = RequestMethod.GET)
	public PagedList<Post> searchPublicFeed(String query,
			PagingParameters pagedListParameters, Facebook facebook) {
		return facebook.feedOperations().searchPublicFeed(query,
				pagedListParameters);
	}

	@RequestMapping(value = "/searchuserfeed/{query}", method = RequestMethod.GET)
	public PagedList<Post> searchUserFeed(String query,
			PagingParameters pagedListParameters, Facebook facebook) {
		return facebook.feedOperations().searchUserFeed(query,
				pagedListParameters);
	}
	
	@RequestMapping(value = "/searchuserfeed/{userId}/{query}", method = RequestMethod.GET)
	public PagedList<Post> searchUserFeed(String userId, String query,
			PagingParameters pagedListParameters, Facebook facebook) {
		return facebook.feedOperations().searchUserFeed(userId, query,
				pagedListParameters);
	}
	
	@RequestMapping(value = "/updatestatus/{message}", method = RequestMethod.GET)
	public String updateStatus(String message, Facebook facebook) {
		return facebook.feedOperations().updateStatus(message);
	}

}
